/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



package sonia.golf.view;

//~--- non-JDK imports --------------------------------------------------------

import android.app.Activity;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import android.widget.ArrayAdapter;
import android.widget.TextView;

import sonia.golf.R;

//~--- JDK imports ------------------------------------------------------------

import java.util.List;

/**
 *
 * @author Sebastian Sdorra
 *
 * @param <T>
 */
public abstract class DoubleAdapter<T> extends ArrayAdapter<T>
{

  /**
   * Constructs ...
   *
   *
   * @param activity
   * @param itemList
   */
  public DoubleAdapter(Activity activity, List<T> itemList)
  {
    super(activity, R.layout.doublelistitem, itemList);
    this.activity = activity;
  }

  //~--- get methods ----------------------------------------------------------

  /**
   * Method description
   *
   *
   * @param item
   *
   * @return
   */
  protected abstract String getLeftTextFromItem(T item);

  /**
   * Method description
   *
   *
   * @param item
   *
   * @return
   */
  protected abstract String getRigthTextFromItem(T item);

  /**
   * Method description
   *
   *
   * @param position
   * @param convertView
   * @param parent
   *
   * @return
   */
  @Override
  public View getView(int position, View convertView, ViewGroup parent)
  {
    View v = convertView;

    if (v == null)
    {
      LayoutInflater li = activity.getLayoutInflater();

      v = li.inflate(R.layout.doublelistitem, parent, false);
    }

    T item = getItem(position);
    TextView textLeft = (TextView) v.findViewById(R.id.list_item_left);

    textLeft.setText(getLeftTextFromItem(item));

    TextView textRight = (TextView) v.findViewById(R.id.list_item_right);

    textRight.setText(getRigthTextFromItem(item));

    return v;
  }

  //~--- fields ---------------------------------------------------------------

  /** Field description */
  private Activity activity;
}
